﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using CosiNet;

namespace TestVM
{
    class Program
    {
        // A little program that prints "Hello World"
        static byte[] hello = {
65, 245, 2, 0, 0, 0, 
65, 253, 250, 0, 0, 0, 
250, 69, 250, 0, 0, 0, 
250, 110, 251, 0, 0, 0, 
250, 116, 252, 0, 0, 0, 
250, 101, 253, 0, 0, 0, 
250, 114, 254, 0, 0, 0, 
250, 32, 255, 0, 0, 0, 
250, 89, 0, 1, 0, 0, 
250, 111, 1, 1, 0, 0, 
250, 117, 2, 1, 0, 0, 
250, 114, 3, 1, 0, 0, 
250, 32, 4, 1, 0, 0, 
250, 78, 5, 1, 0, 0, 
250, 97, 6, 1, 0, 0, 
250, 109, 7, 1, 0, 0, 
250, 101, 8, 1, 0, 0, 
250, 58, 9, 1, 0, 0, 
250, 32, 10, 1, 0, 0, 
65, 247, 17, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
65, 245, 4, 0, 0, 0, 
65, 253, 244, 1, 0, 0, 
235, 1, 0, 0, 0, 0, 
250, 72, 237, 1, 0, 0, 
250, 101, 238, 1, 0, 0, 
250, 108, 239, 1, 0, 0, 
250, 108, 240, 1, 0, 0, 
250, 111, 241, 1, 0, 0, 
250, 44, 242, 1, 0, 0, 
250, 32, 243, 1, 0, 0, 
65, 253, 237, 1, 0, 0, 
68, 247, 7, 0, 0, 0, 
65, 245, 2, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
65, 245, 1, 0, 0, 0, 
65, 246, 10, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
208, 0, 0, 0, 0, 0, 

  };
        /*
         * 65, 245, 1, 0, 0, 0, 
65, 246, 72, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
65, 246, 101, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
65, 246, 108, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
65, 246, 108, 0, 0, 0, 
235, 1, 0, 0, 0, 0, 
65, 246, 111, 0, 0, 0, 
235, 1, 0, 0, 0, 0

         */
        static void Main(string[] args)
        {
             byte[] programLoaded;
             Globals.console = new CosiNetConsole();
            // try
            // {
                if (args.Length == 0)
                {
                    Console.Title = "COSIL - Test Program";
                    Application.Run(hello);
                }
                else if (args.Length == 1)
                {
                    programLoaded = File.ReadAllBytes(args[0]);
                    Console.Title = "COSIL - " + args[0];
                    Application.Run(programLoaded);
                }
           // }
           // catch(Exception ex)
           // {
           //     Console.WriteLine(ex.Message);
           // }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine();
            Console.WriteLine("APP TERMINATED");
            Console.ReadLine();
        }
    }
}
